Load the libraries and the SA data

## Load the libs
# EDA
library(DataExplorer)
## Warning: package 'DataExplorer' was built under R version 4.1.2
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.1.2
library(plotly)
## Warning: package 'plotly' was built under R version 4.1.2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
# Core 
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.1.2
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v tibble  3.1.6     v dplyr   1.0.8
## v tidyr   1.2.0     v stringr 1.4.0
## v readr   2.1.2     v forcats 0.5.1
## v purrr   0.3.4
## Warning: package 'tibble' was built under R version 4.1.2
## Warning: package 'tidyr' was built under R version 4.1.2
## Warning: package 'readr' was built under R version 4.1.2
## Warning: package 'purrr' was built under R version 4.1.2
## Warning: package 'dplyr' was built under R version 4.1.2
## Warning: package 'stringr' was built under R version 4.1.2
## Warning: package 'forcats' was built under R version 4.1.2
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks plotly::filter(), stats::filter()
## x dplyr::lag()    masks stats::lag()
library(timetk)
## Warning: package 'timetk' was built under R version 4.1.2
## Registered S3 method overwritten by 'tune':
##   method                   from   
##   required_pkgs.model_spec parsnip
library(lubridate)
## Warning: package 'lubridate' was built under R version 4.1.2
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
# Accuracy
library(yardstick)
## Warning: package 'yardstick' was built under R version 4.1.2
## For binary classification, the first factor level is assumed to be the event.
## Use the argument `event_level = "second"` to alter this as needed.
## 
## Attaching package: 'yardstick'
## The following object is masked from 'package:readr':
## 
##     spec
# Anomaly
library(anomalize)
## Warning: package 'anomalize' was built under R version 4.1.3
## == Use anomalize to improve your Forecasts by 50%! =============================
## Business Science offers a 1-hour course - Lab #18: Time Series Anomaly Detection!
## </> Learn more at: https://university.business-science.io/p/learning-labs-pro </>
# 1.0 Read DATA -----
# consumption ----
sa_cons <- read.csv("sa/totaldemand_sa.csv")
## Convert Dt
sa_cons<-sa_cons%>%mutate(DATETIME = ymd_hms(DATETIME))

# temperature ----

temp_sa<-read.csv("sa/temprature_sa.csv")
## convert Dt
temp_sa<- temp_sa %>% mutate(DATETIME = ymd_hms(DATETIME))

# forecasted ----
forcst_sa <- read.csv("sa/forecastdemand_sa.csv") 
forcst_sa<- forcst_sa%>% mutate(DATETIME = ymd_hms(DATETIME),LASTCHANGED = ymd_hms(LASTCHANGED))

Plot the time series

sa_cons%>%plot_time_series(.date_var = DATETIME,.value = TOTALDEMAND,.interactive = F)

ACF and PACF

sa_cons%>%filter(DATETIME>="2015-01-01")%>%
  plot_acf_diagnostics(.date_var = DATETIME,.value = TOTALDEMAND,.lags = 0:17520)
## Warning: `gather_()` was deprecated in tidyr 1.2.0.
## Please use `gather()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.

Plot seasonal diagnostics

sa_cons%>%filter(DATETIME>="2015-01-01")%>%
  plot_seasonal_diagnostics(DATETIME, TOTALDEMAND,.feature_set = c("quarter","month.lbl"),.y_lab = "DEMAND")
sa_cons %>%filter(DATETIME>="2015-01-01")%>%
  plot_seasonal_diagnostics(DATETIME, TOTALDEMAND,.feature_set = c("hour","wday.lbl","week"),.y_lab = "DEMAND")